import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
//导入全局样式表
import './assets/css/global.css'
import axios from 'axios'
import TreeTable from 'vue-table-with-tree-grid'
Vue.component("tree-table", TreeTable)

// 导入NProgress 对应的css和js
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

import VueQuillEditor from 'vue-quill-editor'

import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme

Vue.use(VueQuillEditor, /* { default global options } */ )

axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/';

// 在request拦截器中展示滚动条 调动NProgress.start()
axios.interceptors.request.use(config => {
    NProgress.start();
    const token = sessionStorage.getItem('token')
    if (token) { // 判断是否存在token，如果存在的话，则每个http header都加上token
        config.headers.authorization = token //请求头加上token
    }
    return config
})
// 在response拦截器中停止滚动条 调用 NProgress.done()
axios.interceptors.response.use(config=>{
    NProgress.done();
    return config
})
Vue.prototype.$http = axios
Vue.config.productionTip = false
Vue.filter('getDate', function(msg) {

    var date = new Date(msg);

    var yy = date.getFullYear();
    var mm = (date.getMonth() + 1).toString().padStart(2, 0);
    var dd = date.getDate().toString().padStart(2, 0);
    var hh = date.getHours().toString().padStart(2, 0);
    var ss = date.getMinutes().toString().padStart(2, 0);
    var s = date.getSeconds().toString().padStart(2, 0);
    return `${yy}-${mm}-${dd} ${hh}:${ss}:${s}`
})
new Vue({
    router,
    render: h => h(App),
}).$mount('#app')